package com.bonshotels;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Map;
import java.util.Set;

import com.bonshotels.DomainLayer.DomainControllers.CUReservarHabitacio;
import com.bonshotels.Excepcions.ClientNoExisteix;
import com.bonshotels.Excepcions.HabitacioNoExisteix;
import com.bonshotels.Excepcions.HotelNoExisteix;
import com.bonshotels.Excepcions.HotelsNoDisp;
import com.bonshotels.Excepcions.NoHiHaPoblacions;
import com.bonshotels.Excepcions.PoblacioNoExisteix;
import com.bonshotels.Excepcions.ServeiNoDisponible;

public class Main {

	/**
	 * @param args
	 * @throws PoblacioNoExisteix 
	 * @throws HotelNoExisteix 
	 * @throws ClientNoExisteix 
	 * @throws HabitacioNoExisteix 
	 * @throws ServeiNoDisponible 
	 * @throws NoHiHaPoblacions 
	 */
	public static void main(String[] args) throws PoblacioNoExisteix, HotelNoExisteix, ClientNoExisteix, ServeiNoDisponible, HabitacioNoExisteix, NoHiHaPoblacions {
		CUReservarHabitacio cURH = new CUReservarHabitacio();
		Set<String> poblacions = cURH.obtePoblacions();
		for (String s : poblacions) {
			System.out.println(s);
		}
		System.out.println("---------Fi test obtePoblacions----------");
		Calendar c1 = GregorianCalendar.getInstance();
		Date dIni = new Date(0);
		Calendar c2 = GregorianCalendar.getInstance();
		c2.add(Calendar.DAY_OF_MONTH, 5);
		Date dFi = new Date(1500000000);
		try {
			System.out.println("* Busca habitacio a Tarragona");
			Set<Map<String, Object>> habsHots = cURH.buscarHabitacio("Tarragona", dIni, dFi, 1);
			for (Map<String, Object> habHot : habsHots) {
				System.out.println( (String) habHot.get("nomHotel") );
				System.out.println( (String) habHot.get("desc") );
				System.out.println( (String) habHot.get("categoria") );
				System.out.println( ( (Float) habHot.get("avaluacio") ).toString() );				
				Set<Map<String, Object> > habs = (Set<Map<String, Object> >) habHot.get("habs");
				for (Map<String,Object> hab : habs) {
					System.out.println( (String) hab.get("tipusHab") );
					System.out.println( ( (Integer) hab.get("numeroDisp") ).toString() );
					System.out.println( ( (Float) hab.get("preu") ).toString() );
				}
			}
			System.out.println("* Busca habitacio a Barcelona");
			habsHots = cURH.buscarHabitacio("Barcelona", dIni, dFi, 1);
			for (Map<String, Object> habHot : habsHots) {
				System.out.println( (String) habHot.get("nomHotel") );
				System.out.println( (String) habHot.get("desc") );
				System.out.println( (String) habHot.get("categoria") );
				System.out.println( ( (Float) habHot.get("avaluacio") ).toString() );				
				Set<Map<String, Object> > habs = (Set<Map<String, Object> >) habHot.get("habs");
				for (Map<String,Object> hab : habs) {
					System.out.println( (String) hab.get("tipusHab") );
					System.out.println( ( (Integer) hab.get("numeroDisp") ).toString() );
					System.out.println( ( (Float) hab.get("preu") ).toString() );
				}
			}
		} catch (HotelsNoDisp e) {
			e.printStackTrace();
		}
		System.out.println("--------------Fi test buscarHabitacio--------------");
		
		Map<String,Object> infoHab = cURH.selecionarHabitacio("Aprovarem", "Habitacio doble");	
		System.out.println( (String) infoHab.get("pob") );
		DateFormat df = new SimpleDateFormat("dd-MMMMMMMMMMMMMM-yyyy");
		System.out.println( df.format( (Date) infoHab.get("dIni") ) );
		System.out.println( df.format( (Date) infoHab.get("dFi") ) );
		System.out.println( (String) infoHab.get("hotel") );
		System.out.println( (String) infoHab.get("tipusHab") );
		System.out.println( ( (Float) infoHab.get("preuTotal") ).toString() );
		System.out.println("--------------Fi test seleccionarHabitacio--------------");
		
		Map<String,Object> habClient = cURH.introduirDni("dni1");
		System.out.println( (String) habClient.get("pob") );
		System.out.println( df.format( (Date) habClient.get("dIni") ) );
		System.out.println( df.format( (Date) habClient.get("dFi") ) );
		System.out.println( (String) habClient.get("hotel") );
		System.out.println( (String) habClient.get("tipusHab") );
		System.out.println( (String) habClient.get("dni"));
		System.out.println( (String) habClient.get("nomClient"));
		System.out.println( (String) habClient.get("cognoms"));
		System.out.println( (String) habClient.get("email"));
		System.out.println( ( (Float) habClient.get("preuTotal") ).toString() );
		System.out.println("--------------Fi test introduirDni--------------");
		
		cURH.pagament("", new Date(0) );
		System.out.println("--------------Fi test pagament--------------");
	}

}
